const {
  Login,
  Updated,
  Details,
  wechatList,
} = require('../../controllers/wechat/users.js')

const { verifyToken } = require('../../utils/jwt.js')

const opts = {
  schema: {
    body: {
      type: 'object',
      required: ['phoneNo', 'password'],
      properties: {
        phoneNo: { type: 'string' },
        password: { type: 'string' },
      },
    },
  },
}

const wechatUsers = (fastify, options, done) => {
  /**
   * 小程序 登录
   */
  fastify.post('/wechat/login', { ...opts }, Login)
  done()

  /**
   * 获取用户详情
   */
  fastify.get('/wechat/user/:userNo', Details)
  done()

  /**
   * 更新 用户信息
   */
  fastify.put('/wechat/user/:userNo', { preHandler: verifyToken }, Updated)
  done()
  /**
   * 注销账户
   */
  fastify.delete('/wechat/user/:userNo', { preHandler: verifyToken }, Updated)
  done()
}

module.exports = wechatUsers
